# extensions.py 扩展文件
import bleach
import pymongo
from flask_mail import Mail
import logging
from logging.handlers import TimedRotatingFileHandler
# 链接数据库
client = pymongo.MongoClient('localhost')
db = client.Sylven
# collection = db.blog

CaptchaDB  = db.captcha
UserMongodb = db.UserMongodb
BlogMongodb = db.BlogMongodb
blogDB = db.blog



ALLOWED_TAGS = bleach.sanitizer.ALLOWED_TAGS | {
    'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'code', 'blockquote', 'hr'
}
ALLOWED_ATTRIBUTES = bleach.sanitizer.ALLOWED_ATTRIBUTES.copy()
ALLOWED_ATTRIBUTES['code'] = ['class']

mail = Mail()


# 创建一个日志管理系统
all_logger = logging.getLogger('all')
all_logger.setLevel(logging.DEBUG)

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.ERROR)
file_handler = TimedRotatingFileHandler('E:/ai/flask/gitee_front_end_project/ncst_acmer_management_system/log/all.log' , when='D' , backupCount=90 , encoding='utf-8')
file_handler.setLevel(logging.DEBUG)

formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(filename)s - %(lineno)d  - %(name)s - %(message)s")
console_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)

all_logger.addHandler(console_handler)
all_logger.addHandler(file_handler)
